package com.heima.wemedia.controller.v1;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.dtos.WmMaterialDTO;
import com.heima.wemedia.service.WmMaterialService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
@Api(value = "素材管理API",tags = "素材管理API")
@RestController
@RequestMapping("/api/v1/material")
public class WmMaterialController {
    @Autowired
    private WmMaterialService materialService;

    /**
     * 上传图片
     *
     * @param multipartFile multipart 文件 （@RequestParam默认存在，可以省去）
     * @return 通用的结果返回类
     */
    @ApiOperation("上传素材")
    @PostMapping("/upload_picture")
    public ResponseResult uploadPicture(@RequestParam MultipartFile multipartFile) {
        return materialService.uploadPicture(multipartFile);
    }

    @ApiOperation("查询自己的素材")
    @PostMapping("/list")
    public ResponseResult list(@RequestBody WmMaterialDTO wmMaterialDTO) {
        return materialService.findListByWmUserId(wmMaterialDTO);
    }

    @ApiOperation("用户删除自己的素材")
    @GetMapping("/del_picture/{materialId}")
    public ResponseResult deleteMaterial(@PathVariable("materialId") Integer materialId) {
        return materialService.delPicture(materialId);
    }

    @ApiOperation("用户收藏心仪的素材")
    @GetMapping("/collect/{materialId}")
    public ResponseResult collectMaterialById(@PathVariable("materialId") Integer materialId) {
        return materialService.updateMaterialCollection(materialId, (short) 1);
    }

    @ApiOperation("用户取消收藏心仪的素材")
    @GetMapping("/cancel_collect/{materialId}")
    public ResponseResult cancelCollectMaterialById(@PathVariable("materialId") Integer materialId) {
        return materialService.updateMaterialCollection(materialId, (short) 0);
    }
}